package com.dawan.springboot.controller;

import com.dawan.springboot.service.SecurityCodeService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author: dawan
 * @Date: 2017-11-07
 * @Desc: 验证码识别
 */
@Controller
@RequestMapping("OcrCode")
public class SecurityCodeController {

    @Resource private SecurityCodeService securityCodeService;
    
    
    /**
     * @Author: chenhan     2017/11/7
     * @Desc: 验证码识别控制器
     * 
     */
    @RequestMapping("/get.do")
    @ResponseBody
    public Map GetSecurityCode(){
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            String[] dres  = securityCodeService.downloadImage("http://jwgl.suse.edu.cn//CheckCode.aspx", "CheckCode.png");
            String secretcode = securityCodeService.getAllOcr("CheckCode.png");
            System.out.println("codeis:"+secretcode);
            result.put("status", dres[0]);
            result.put("code", secretcode);
            result.put("cookie", dres[1]);
        } catch (Exception e) {
            result.put("status", "false");
            result.put("code", "");
            result.put("cookie", "");
            e.printStackTrace();
        }
        return result;
    }

}
